#include "aky_com_include.h"

void aky_gpio_init(void)
{

    P0M = 0Xff;
    P0UR = 0X00;
    P0 = 0X00;

    P1OC = 0x00; // disable open-drain output mode
    P1M = 0Xff;
    P1UR = 0X00;
    P1 = 0X00;

    P2M = 0Xfc;
    P2UR = 0X00;
    P2 = 0X00;

    P3M = 0Xff;
    P3UR = 0X00;
    P3 = 0X00;

    P4M = 0Xff;
    P4UR = 0X00;
    P4 = 0X00;

	P3CON =(0xff);	
	P4CON =(0xff);	
    P5CON = 0xff;

    P5M = 0Xff;
    P5UR = 0X00;
    P5 = 0X00;

    KEY_POWER_PROT_REG &= ~KEY_POWER_PIN; // IO端口方向
    KEY_POWER_UP_REG |= KEY_POWER_PIN;    // 上拉配置

    KEY_SET_PROT_REG &= ~KEY_SET_PIN; // IO端口方向
    KEY_SET_UP_REG |= KEY_SET_PIN;    // 上拉配置

    KEY_MEM_PROT_REG &= ~KEY_MEM_PIN; // IO端口方向
    KEY_MEM_UP_REG |= KEY_MEM_PIN;    // 上拉配置

    FULL_PROT_REG &= ~FULL_PIN; // IO端口方向
    FULL_UP_REG |= FULL_PIN;    // 上拉配置

    CHARGE_PROT_REG &= ~CHARGE_PIN; // IO端口方向
    CHARGE_UP_REG |= CHARGE_PIN;    // 上拉配置

    BT_POWER_PROT_REG |= BT_POWER_PIN; // IO端口方向
    BT_POWER_UP_REG &= ~BT_POWER_PIN;  // 上拉配置

    // 外部低频晶振IO配置
    P2M &= ~(0x03); // 晶振引脚输入
    P2UR &= ~(0x03);

    P0M |= (0x01 << 7); // pump 引脚输出
    P0UR &= ~(0x01 << 7);


    BT_POWER_OFF;
}


void aky_gpio_enter_stop_mode(void)
{
    aky_gpio_init();
    aky_disp_init();

    // 串口
    P0M |= (0x30); //
    P0UR &= ~(0x30);

    // 外部低频晶振IO配置
    P2M &= ~(0x03); // 晶振引脚输入
    P2UR &= ~(0x03);

    P0M |= (0x01 << 7); // pump 引脚输出
    P0UR &= ~(0x01 << 7);

    P1M &= ~(0x01 << 0 | 0x01 << 1);// lbt pin
    P1UR |= (0x01 << 0 | 0x01 << 1); 

    VALVE_PROT_REG |= VALVE_PIN; // IO端口方向
    VALVE_UP_REG &= ~VALVE_PIN;  // 上拉配置
    VALVE_OFF;
    PUMP_OFF;

    BT_POWER_OFF;

    LCD_BL_OFF;
    LCD_POWER_OFF;
    RESET_L;
    RS_L;
    CS_L;
    WR_L;
    RD_L;
    SCL_L;
    SDA_L;
    P4 = 0x00;

    SDADC_POWER_OFF;
}
